﻿#ifndef __AVOID_CONTROL_SINGLE_LABEL_HEAD_FILE_INCLUDED__
#define __AVOID_CONTROL_SINGLE_LABEL_HEAD_FILE_INCLUDED__
#include "ctlStatic.h"
#include "interface/IFont.h"

namespace swui
{
#pragma warning(push)
#pragma warning(disable:4250)
	class ctlSingleLabel : 
		virtual public ctlStatic, public IFont
	{
	public:
		static const ctlControlType uniqueType = ctlControlType::ctlSingleLabel;
		static const ctlRect defaultPaddingRect;
	public:
		virtual ~ctlSingleLabel() { destroy(); }
		bool create(ctlRoot* parent, ctlRect rect, const ctlText& = L"");
	public:
		void setTextColor(ctlColor);
		ctlColor getTextColor();
		void setPadding(ctlRect padding);
		ctlRect getPadding();
	public:
		void autoSize();
	protected:
		void _redraw_(_ctlInterior::drawInfo*);
	private:
		ctlColor _single_label_text_color;
		ctlRect _single_label_padding_rect;
	};
#pragma warning(pop)
	inline bool ctlSingleLabel::create(ctlRoot* parent, ctlRect rect, const ctlText& text)
	{
		if(ctlStatic::create(parent, rect) == false)
			return false;
		_control_virtual_class_end = this;
		_controlType = ctlControlType::ctlSingleLabel;
		_single_label_text_color = 0xff000000;
		_single_label_padding_rect = ctlSingleLabel::defaultPaddingRect;
		_virtual_font_create();
		setTextAlignMode(IFont::textAlign::left);
		setText(text);
		if(rect.cx == 0 && rect.cy == 0) 
			autoSize();
		return true;
	}
	inline void ctlSingleLabel::setPadding(ctlRect rect) {
		_single_label_padding_rect = rect;
		redraw();
	}
	inline ctlRect ctlSingleLabel::getPadding() {
		return _single_label_padding_rect;
	}
	inline void ctlSingleLabel::setTextColor(ctlColor color) {
		_single_label_text_color = color;
		redraw();
	}
	inline ctlColor ctlSingleLabel::getTextColor() {
		return _single_label_text_color;
	}
	inline void ctlSingleLabel::autoSize() {
		ctlPoint sz = getFont()->getTextSize(_textpack.wptr(), -1, true);
		sz.x += _single_label_padding_rect.cx + _single_label_padding_rect.x;
		sz.y += _single_label_padding_rect.cy + _single_label_padding_rect.y;
		size(sz);
	}
}

#endif